<template>
  <div>
    <div class="form">
      <form action="" @submit.prevent="submit">
        <div class="user">
          <my-input placeholder="邮箱地址" v-model="users.user" pattern="^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$">
            <i class="fa fa-user-o"></i>
          </my-input>
        </div>
        <button :disabled="dis" :class="{success:!dis}">获取验证码</button>
      </form>
    </div>

  </div>
</template>
<script>
  // http://u.ishuhui.com/password/send_code
  import MyInput from '../components/MyInput'
  import bus from '../bus.js'
  export default {
    data() {
      return {
        users: {
          user: ""
        },
        show: true,
        dis: true,
        bl: true
      }
    },
    components: {
      MyInput
    },
    methods: {
      mychange() {
        if (this.bl) {
          var reg = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/
          if (reg.test(this.users.user)) {
            this.dis = false
          } else {
            this.dis = true
          }
        }
      },
      submit() {
        console.log('提交数据')
        this.axios.post('http://u.ishuhui.com/password/send_code', this.users)
          .then(data => {
            console.log(data)
            if (data.errNo == 0) {
              console.log('1')
              console.log(data)
            } else {
              this.$message.error('帐号不存在');
            }
          })
          .catch(err => {
            console.log(err)
          })
      }
    },
    mounted() {
      bus.$on('changes', this.mychange)
    },
  }

</script>
<style scoped>
  .form {
    width: 100%;
    font-size: .4rem;
    margin-top: 10px;
  }
  
  .form i {
    color: #ccc;
  }
  
  .form form>div {
    width: 100%;
    padding: 10px 15px;
    background-color: white;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
  }
  
  .form button {
    width: 90%;
    height: 45px;
    display: block;
    margin: 20px auto;
    line-height: 45px;
    text-align: center;
    font-size: .4rem;
    border: 1px solid #ccc;
    border-radius: 5px;
  }
  
  .success {
    color: white;
    background-color: #ff4400;
  }

</style>
